<?php

class Controller_Error extends Controller
{
	static function notAvailable()
	{
		header('HTTP/1.0 503 Service Unavailable');
		$view = new View();
		$view->add('pagetitle', 'Сервер временно недоступен');
		ob_clean();
		echo $view->render('errors/not-available.tpl');
		exit;
	}
	
	
	static function forbidden($title = 'Доступ запрещен', $comment = '')
	{
		header("HTTP/1.0 401 Unauthorized");
		$view = new View();
		$view->add('comment',$comment);
		$view->add('pagetitle',$title);
		ob_clean();
		echo $view->render('errors/forbidden.tpl');
		exit;
	}
	
	
	static function loginforbidden($title='Доступ запрещен', $comment='')
	{
		header("HTTP/1.0 401 Unauthorized");
		$view = new View();
		$view->add('comment',$comment);
		$view->add('pagetitle',$title);
		ob_clean();
		echo $view->render('invite/forbidden.tpl');
		exit;
	}
	
	
	static function notFound($title='Страница не найдена', $comment='')
	{
		$uri = substr($_SERVER['REQUEST_URI'],1);
		if(is_int(strpos($uri,'?'))) 
		$uri=substr($uri,0,strpos($uri,'?'));
		$urii = strtolower($uri);
		
		header("HTTP/1.0 404 Not Found");
		$view = new View('wrapper.tpl');
		$view->add('url',$urii);
		$view->add('pagetitle',$title);
        $view->add('comment',$comment);
		ob_clean();
		echo $view->render('errors/404.tpl');
		exit;
	}
	
	
	static function internalError($title='Внутренняя ошибка',$comment='')
	{
		$uri = substr($_SERVER['REQUEST_URI'],1);
		if(is_int(strpos($uri,'?'))) 
		$uri=substr($uri,0,strpos($uri,'?'));
		$urii = strtolower($uri);
		
		header("HTTP/1.0 500 Internal Server Error");
		$view = new View('wrapper.tpl');
		$view->add('url',$urii);
		$view->add('pagetitle',$title);
        $view->add('comment',$comment);
		ob_clean();
		echo $view->render('errors/internal.tpl');
		exit;
	}
}